package com.qf.dao.impl;


import com.qf.dao.DepositDao;
import com.qf.model.Banktable;
import com.qf.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class DepositDaoImpl implements DepositDao {
    private QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());

    //存定期
    @Override
    public int periodical(Banktable banktable) {
        String sql = "insert into banktable values (null,?,?,?,?,?)";
        try {
            int update = queryRunner.update(sql, banktable.getCid(), banktable.getAmountMoney(), banktable.getRate(), banktable.getDate(), banktable.getAmountTime());
            return update;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
    //根据卡号查询是否有定期
    @Override
    public Banktable findByCid(String cid) {
        String sql = "select * from banktable where cid =?";

        try {
            Banktable query = queryRunner.query(sql, new BeanHandler<>(Banktable.class),cid);
            return query;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
